<template>
    <div>
    <el-breadcrumb separator="/">
        <el-breadcrumb-item>数据审核</el-breadcrumb-item>
        <el-breadcrumb-item>表格审核</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <!-- 合约主管 基础清单 -->
      <div class="baseList" v-if="roleName=='合约主管'">
        <el-row>
          <el-col :span="17"><span class="title">合约主管-基础清单表</span></el-col>
          <el-col :span="7">
            <el-input placeholder="请输入excel表名称" v-model="baseQuery.query" @keyup.enter="getBaseList()" clearable @clear="getBaseList()">
              <template #append> <el-button icon="el-icon-search" @click="getBaseList()"></el-button></template>
            </el-input>
          </el-col>
        </el-row>
        <el-table :data="baseList" border stripe style="margin-bottom:15px">
          <el-table-column type="index" label="序号"></el-table-column>
          <el-table-column label="excel名称" prop="excelName"></el-table-column>
          <el-table-column label="上报时间" prop="createTime"><template v-slot="scope">{{DateFormat(scope.row.createTime)}}</template></el-table-column>
          <el-table-column label="上报员" prop="reportUserId"></el-table-column>
          <el-table-column label="操作" min-width="150">
          <template v-slot="scope">
            <el-button type="warning" icon="el-icon-edit" size="mini" @click="showBaseExcel(scope.row)" >查看excel表</el-button>
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="acceptBase(scope.row)" >通过</el-button>
            <el-button type="danger" icon="el-icon-edit" size="mini" @click="rejectBase(scope.row)" >不通过</el-button>
          </template>
        </el-table-column>
        </el-table>
        <el-config-provider :locale="locale">
          <el-pagination @size-change="baseSizeChange" @current-change="baseCurChange" :current-page="baseQuery.pagenum" 
            :page-sizes="[5,10,20]" :page-size="baseQuery.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="baseTotal">
          </el-pagination>
        </el-config-provider>
        <el-dialog title="数据审核" v-model="rejBaseDiaVisible" width="50%" @close="rejBaseDiaClosed">
          <el-form ref="rejBaseForm" :model="curBase" label-width="80px" width="100%">
            <el-form-item label="驳回原因" prop="reason"><el-input type="text" v-model="curBase.reason"></el-input></el-form-item>
          </el-form>
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="rejBaseDiaVisible = false">取消</el-button>
              <el-button type="primary" @click="rejBase">确定</el-button>
            </span>
          </template>
        </el-dialog>
      </div>
      <!-- 合约主管 甩项 -->
      <div class="jilt" v-if="roleName=='合约主管'">
        <el-row>
          <el-col :span="17"><span class="title">合约主管-甩项工程量</span></el-col>
          <el-col :span="7">
            <el-input placeholder="请输入excel表名称" v-model="jiltQuery.query" @keyup.enter="getJilt()" clearable @clear="getJilt()">
              <template #append> <el-button icon="el-icon-search" @click="getJilt()"></el-button></template>
            </el-input>
          </el-col>
        </el-row>
        <el-table :data="Jilt" border stripe style="margin-bottom:15px">
          <el-table-column type="index" label="序号"></el-table-column>
          <el-table-column label="excel名称" prop="excelName"></el-table-column>
          <el-table-column label="上报时间" prop="createTime"><template v-slot="scope">{{DateFormat(scope.row.createTime)}}</template></el-table-column>
          <el-table-column label="上报员" prop="reportUserId"></el-table-column>
          <el-table-column label="操作" min-width="150">
          <template v-slot="scope">
            <el-button type="warning" icon="el-icon-edit" size="mini" @click="showJiltExcel(scope.row)" >查看excel表</el-button>
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="acceptJilt(scope.row)" >通过</el-button>
            <el-button type="danger" icon="el-icon-edit" size="mini" @click="rejectJilt(scope.row)" >不通过</el-button>
          </template>
        </el-table-column>
        </el-table>
        <el-config-provider :locale="locale">
          <el-pagination @size-change="jiltSizeChange" @current-change="jiltCurChange" :current-page="jiltQuery.pagenum" 
            :page-sizes="[5,10,20]" :page-size="jiltQuery.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="jiltTotal">
          </el-pagination>
        </el-config-provider>
        <el-dialog title="数据审核" v-model="rejJiltDiaVisible" width="50%" @close="rejJiltDiaClosed">
          <el-form ref="rejJiltForm" :model="curJilt" label-width="80px" width="100%">
            <el-form-item label="驳回原因" prop="reason"><el-input type="text" v-model="curJilt.reason"></el-input></el-form-item>
          </el-form>
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="rejJiltDiaVisible = false">取消</el-button>
              <el-button type="primary" @click="rejJilt">确定</el-button>
            </span>
          </template>
        </el-dialog>
      </div>

      <!-- 施工主管 进度 -->
      

      <!-- 资料主管 资料 -->
      <div class="document" v-if="roleName=='资料主管'">
        <el-row>
          <el-col :span="17"><span class="title">资料主管-资料表</span></el-col>
          <el-col :span="7">
            <el-input placeholder="请输入excel表名称" v-model="docQuery.query" @keyup.enter="getDocument()" clearable @clear="getDocument()">
              <template #append> <el-button icon="el-icon-search" @click="getDocument()"></el-button></template>
            </el-input>
          </el-col>
        </el-row>
        <el-table :data="document" border stripe style="margin-bottom:15px">
          <el-table-column type="index" label="序号"></el-table-column>
          <el-table-column label="excel名称" prop="excelName"></el-table-column>
          <el-table-column label="上报时间" prop="createTime"><template v-slot="scope">{{DateFormat(scope.row.createTime)}}</template></el-table-column>
          <el-table-column label="上报员" prop="reportUserId"></el-table-column>
          <el-table-column label="操作" min-width="150">
          <template v-slot="scope">
            <el-button type="warning" icon="el-icon-edit" size="mini" @click="showDocExcel(scope.row)" >查看excel表</el-button>
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="acceptDoc(scope.row)" >通过</el-button>
            <el-button type="danger" icon="el-icon-edit" size="mini" @click="rejectDoc(scope.row)" >不通过</el-button>
          </template>
        </el-table-column>
        </el-table>
        <el-config-provider :locale="locale">
          <el-pagination @size-change="docSizeChange" @current-change="docCurChange" :current-page="docQuery.pagenum" 
            :page-sizes="[5,10,20]" :page-size="docQuery.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="docTotal">
          </el-pagination>
        </el-config-provider>
        <el-dialog title="数据审核" v-model="rejDocDiaVisible" width="50%" @close="rejDocDiaClosed">
          <el-form ref="rejDocForm" :model="curDoc" label-width="80px" width="100%">
            <el-form-item label="驳回原因" prop="reason"><el-input type="text" v-model="curDoc.reason"></el-input></el-form-item>
          </el-form>
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="rejDocDiaVisible = false">取消</el-button>
              <el-button type="primary" @click="rejDoc">确定</el-button>
            </span>
          </template>
        </el-dialog>
      </div>

      <!-- 实验员 试验检测表 -->
      <div class="experiment" v-if="roleName=='实验主管'">
        <el-row>
          <el-col :span="17"><span class="title">实验主管-试验检测表</span></el-col>
          <el-col :span="7">
            <el-input placeholder="请输入excel表名称" v-model="docQuery.query" @keyup.enter="getExperiment()" clearable @clear="getExperiment()">
              <template #append> <el-button icon="el-icon-search" @click="getExperiment()"></el-button></template>
            </el-input>
          </el-col>
        </el-row>
        <el-table :data="experiment" border stripe style="margin-bottom:15px">
          <el-table-column type="index" label="序号"></el-table-column>
          <el-table-column label="excel名称" prop="excelName"></el-table-column>
          <el-table-column label="上报时间" prop="createTime"><template v-slot="scope">{{DateFormat(scope.row.createTime)}}</template></el-table-column>
          <el-table-column label="上报员" prop="reportUserId"></el-table-column>
          <el-table-column label="操作" min-width="150">
          <template v-slot="scope">
            <el-button type="warning" icon="el-icon-edit" size="mini" @click="showExpExcel(scope.row)" >查看excel表</el-button>
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="acceptExp(scope.row)" >通过</el-button>
            <el-button type="danger" icon="el-icon-edit" size="mini" @click="rejectExp(scope.row)" >不通过</el-button>
          </template>
        </el-table-column>
        </el-table>
        <el-config-provider :locale="locale">
          <el-pagination @size-change="expSizeChange" @current-change="expCurChange" :current-page="expQuery.pagenum" 
            :page-sizes="[5,10,20]" :page-size="expQuery.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="expTotal">
          </el-pagination>
        </el-config-provider>
        <el-dialog title="数据审核" v-model="rejExpDiaVisible" width="50%" @close="rejExpDiaClosed">
          <el-form ref="rejExpForm" :model="curExp" label-width="80px" width="100%">
            <el-form-item label="驳回原因" prop="reason"><el-input type="text" v-model="curExp.reason"></el-input></el-form-item>
          </el-form>
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="rejExpDiaVisible = false">取消</el-button>
              <el-button type="primary" @click="rejExp">确定</el-button>
            </span>
          </template>
        </el-dialog>
      </div>

    </el-card>
    </div>
</template>

<script>
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import dateFormatFun from "../../plugins/dateFormat";
export default {
  data(){
    return{
      document:[],
      docQuery:{
        query:"", pagenum:1, pagesize:5
      },
      docTotal:0,
      rejDocDiaVisible:false,
      curDoc:{},

      experiment:[],
      expQuery:{
        query:"", pagenum:1, pagesize:5
      },
      expTotal:0,
      rejExpDiaVisible:false,
      curExp:{},

      baseList:[],
      baseQuery:{
        query:"", pagenum:1, pagesize:5
      },
      baseTotal:0,
      rejBaseDiaVisible:false,
      curBase:{},

      jilt:[],
      jiltQuery:{
        query:"", pagenum:1, pagesize:5
      },
      jiltTotal:0,
      rejJiltDiaVisible:false,
      curJilt:{},

      progress:[],
      proQuery:{
        query:"", pagenum:1, pagesize:5
      },
      proTotal:0,
      rejProDiaVisible:false,
      curPro:{},

      roleName:"",
    }
  },
  setup() {
    return {
      locale: zhCn
    };
  },
  mounted(){
    this.roleName = window.sessionStorage.getItem('roleName') 
    
    if(this.roleName == "资料主管"){ this.getDocument(); }
    if(this.roleName == "实验主管"){ this.getExperiment(); }
    if(this.roleName == "施工主管"){ this.getProgress(); }  
    if(this.roleName == "合约主管"){ this.getBaseList(); this.getJilt();}  
  },
  computed:{
    DateFormat(){
      return function(date){
        return dateFormatFun(date,2);
      };
    }
  },
  methods:{
  // 资料表
    async getDocument() {
      const { data: res } = await this.$http.get("documentSupervisor/getReviewDocumentExcel",{params: this.docQuery});
      if (res.code !== 200) return this.$message.error(res.msg);
      this.document = res.data.list;
      this.docTotal = res.data.total;
    },
    docSizeChange(newSize) {
      this.docQuery.pagesize = newSize;
      this.getDocument();
    },
    docCurChange(newPage) {
      this.docQuery.pagenum = newPage;
      this.getDocument();
    },
    async acceptDoc(document){
      const confirmRes = await this.$confirm("确认通过该条数据？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).catch(err => console.log(err));
      if (confirmRes !== "confirm") {return this.$message.info("取消通过");}
      let formData = new FormData();
      formData.append("id",document.id)
      const { data: res } = await this.$http.post("documentSupervisor/acceptDocumentExcel",formData);
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.getDocument()
    },
    rejectDoc(document){
      this.curDoc = document;
      this.rejDocDiaVisible = true;
    },
    rejDocDiaClosed(){ this.$refs.rejDocForm.resetFields()},
    async rejDoc(){
      let formData = new FormData();
      formData.append('id',this.curDoc.id);
      formData.append('reason',this.curDoc.reason);
      const { data: res } = await this.$http.post('documentSupervisor/rejectDocumentExcel',formData)
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.rejDocDiaVisible = false 
      this.getDocument()
    },
    showDocExcel(excel){
      this.$message.warning("在线预览 资料 excel");
    },

  // 试验检测表
    async getExperiment() {
      const { data: res } = await this.$http.get("experimentSupervisor/getReviewExperimentExcel",{params: this.expQuery});
      if (res.code !== 200) return this.$message.error(res.msg);
      this.experiment = res.data.list;
      this.expTotal = res.data.total;
    },
    expSizeChange(newSize) {
      this.expQuery.pagesize = newSize;
      this.getExperiment();
    },
    expCurChange(newPage) {
      this.expQuery.pagenum = newPage;
      this.getExperiment();
    },
    async acceptExp(experiment){
      const confirmRes = await this.$confirm("确认通过该条数据？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).catch(err => console.log(err));
      if (confirmRes !== "confirm") {return this.$message.info("取消通过");}
      let formData = new FormData();
      formData.append("id",experiment.id)
      const { data: res } = await this.$http.post("experimentSupervisor/acceptExperimentExcel",formData);
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.getExperiment()
    },
    rejectExp(experiment){
      this.curExp = experiment;
      this.rejExpDiaVisible = true;
    },
    rejExpDiaClosed(){ this.$refs.rejExpForm.resetFields()},
    async rejExp(){
      let formData = new FormData();
      formData.append('id',this.curExp.id);
      formData.append('reason',this.curExp.reason);
      const { data: res } = await this.$http.post('experimentSupervisor/rejectExpumentExcel',formData)
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.rejExpDiaVisible = false 
      this.getExperiment()
    },
    showExpExcel(excel){
      this.$message.warning("在线预览 试验检测 excel");
    },

  // 基础清单表
    async getBaseList() {
      const { data: res } = await this.$http.get("contractSupervisor/getReviewBaseExcel",{params: this.baseQuery});
      if (res.code !== 200) return this.$message.error(res.msg);
      this.baseList = res.data.list;
      this.baseTotal = res.data.total;
    },
    baseSizeChange(newSize) {
      this.baseQuery.pagesize = newSize;
      this.getBaseList();
    },
    baseCurChange(newPage) {
      this.baseQuery.pagenum = newPage;
      this.getBaseList();
    },
    async acceptBase(baseList){
      const confirmRes = await this.$confirm("确认通过该条数据？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).catch(err => console.log(err));
      if (confirmRes !== "confirm") {return this.$message.info("取消通过");}
      let formData = new FormData();
      formData.append("id",baseList.id)
      const { data: res } = await this.$http.post("contractSupervisor/acceptBaseExcel",formData);
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.getBaseList()
    },
    rejectBase(baseList){
      this.curBase = baseList;
      this.rejBaseDiaVisible = true;
    },
    rejBaseDiaClosed(){ this.$refs.rejBaseForm.resetFields()},
    async rejBase(){
      let formData = new FormData();
      formData.append('id',this.curBase.id);
      formData.append('reason',this.curBase.reason);
      const { data: res } = await this.$http.post('contractSupervisor/rejectBaseExcel',formData)
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.rejBaseDiaVisible = false 
      this.getBaseument()
    },
    showBaseExcel(excel){
      this.$message.warning("在线预览 基础清单 excel");
    },

  // 甩项工程量
    async getJilt() {
      const { data: res } = await this.$http.get("contractSupervisor/getReviewJiltExcel",{params: this.jiltQuery});
      if (res.code !== 200) return this.$message.error(res.msg);
      this.jilt = res.data.list;
      this.jiltTotal = res.data.total;
    },
    baseSizeChange(newSize) {
      this.baseQuery.pagesize = newSize;
      this.getBaseList();
    },
    baseCurChange(newPage) {
      this.baseQuery.pagenum = newPage;
      this.getBaseList();
    },
    async acceptBase(baseList){
      const confirmRes = await this.$confirm("确认通过该条数据？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).catch(err => console.log(err));
      if (confirmRes !== "confirm") {return this.$message.info("取消通过");}
      let formData = new FormData();
      formData.append("id",baseList.id)
      const { data: res } = await this.$http.post("contractSupervisor/acceptBaseExcel",formData);
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.getBaseList()
    },
    rejectBase(baseList){
      this.curBase = baseList;
      this.rejBaseDiaVisible = true;
    },
    rejBaseDiaClosed(){ this.$refs.rejBaseForm.resetFields()},
    async rejBase(){
      let formData = new FormData();
      formData.append('id',this.curBase.id);
      formData.append('reason',this.curBase.reason);
      const { data: res } = await this.$http.post('contractSupervisor/rejectBaseExcel',formData)
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.rejBaseDiaVisible = false 
      this.getBaseument()
    },
    showBaseExcel(excel){
      this.$message.warning("在线预览 基础清单 excel");
    },

  // 进度表

  }
}
</script>

<style lang="less" scoped>
.title{
    font-size: 14px;
    color:#666;
    display: block;
    padding:10px 0 0 2px;
  }
</style>